package appli;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;

import logs.LogLevelEnum;
import logs.LogTypesEnum;

public class Logger implements LoggerInterface {

	private File logFile;
	private SimpleDateFormat formater;
	private final String format = "dd/MM/yy H:mm:ss";
	private PrintWriter out;

	public Logger() {
		try {
			formater = new java.text.SimpleDateFormat(format);
			java.util.Date date = new java.util.Date();
			String formatDateFichier = "dd-MM-yy_H_mm_ss";
			SimpleDateFormat formaterDateFichier = new java.text.SimpleDateFormat(
					formatDateFichier);
			String timeStamp = formaterDateFichier.format(date);
			logFile = new File("./logs/logSIM_" + timeStamp + ".txt");
			out = new PrintWriter(new FileWriter(logFile, true));
			out.write("FICHIER LOG DU : " + timeStamp);
			out.println();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void log(LogLevelEnum logLevel, LogTypesEnum logType, String log) {
		java.util.Date date = new java.util.Date();
		String timeStamp = formater.format(date);
		try {
			out = new PrintWriter(new FileWriter(logFile, true));
		} catch (IOException e) {
			e.printStackTrace();
		}
		out.println();
		out.write(timeStamp + " [" + logLevel + "] -"+logType+"- " + log);
		out.close();
	}

}
